<template>
  <a-modal
    :visible="visible"
    :title="title"
    @cancel="cancel"
    @ok="ok()"
  >
    <a-form-model :model="data" ref="data" :rules="rules" :labelCol="{span:8}" :wrapperCol="{span:10}">
      <a-form-model-item has-feedback label="名称" prop="name" placeholder="不能只有数字">
        <a-input v-model="data.name"></a-input>
      </a-form-model-item>
      <a-form-model-item has-feedback label="模型标示" prop="key" placeholder="不能只有数字">
        <a-input v-model="data.key"></a-input>
      </a-form-model-item>
      <a-form-model-item has-feedback label="类别" prop="category" placeholder="不能只有数字">
        <a-input v-model="data.category"></a-input>
      </a-form-model-item>
      <a-form-model-item v-if="isAdd===true" label="描述">
        <a-input type="textarea" v-model="data.des"></a-input>
      </a-form-model-item>
    </a-form-model>
  </a-modal>
</template>

<script>
  import { EditFormMixin } from '@/mixins/EditFormMixin'

  export default {
    name: 'ManageEditModel',
    mixins: [EditFormMixin],
    data() {
      return {
        visible: false,
        isAdd: false,
        data: {
          name: '',
          key: '',
          category: '',
          des: ''
        },
        title: '',
        rules: {
          name: [{ required: true, message: '名称不能为空', target: ['change', 'blur'] }],
          key: [{ required: true, message: '模型标示不能为空', target: ['change', 'blur'] }],
          category: [{ required: true, message: '类别不能为空', target: ['change', 'blur'] }]
        },
        url: {
          add: '/act/model/createModel',
          update: '/act/model/updateModel'
        }
      }
    },
    methods: {
      cancel() {
        this.visible = false
        this.$emit('reloadPage')
      },
      ok() {
        this.$refs.data.validate(valid => {
          if (valid) {
            if (this.isAdd) {
              //新增
              this.add(this.data)
            } else {
              //修改
              this.edit(this.data)
            }
          } else {
            this.$message.error('请检查参数')
          }
        })
      }
    }
  }
</script>

<style scoped>

</style>